import 'package:flutter/material.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: Text("抽屉菜单组件"),
        ),
        body: Text("抽屉组件"),
        drawer: Drawer(
          child: Column(
            children: <Widget>[
              //抽屉头部
              Row(
                children: <Widget>[
                  Expanded(child: UserDarwerHeader()),
                ],
              ),
              ListTile(
                leading: Icon(Icons.settings),
                title: Text("设置"),
              ),
              Divider(), //分割线组件
              ListTile(
                leading: Icon(Icons.home),
                title: Text("首页"),
              ),
              Divider(),
              ListTile(
                leading: Icon(Icons.search),
                title: Text("搜索"),
              ),
              Divider(),
            ],
          ),
        ),
        //右侧抽屉
        endDrawer: Drawer(
          child: ListView(
            children: [
              DrawerHeader(
                child: Text('设置'),
                decoration: BoxDecoration(color: Colors.grey[100]),
              ),
              Builder(
                builder: (ctx) => ListTile(
                  title: Text('Option A'),
                  onTap: () => Navigator.pop(ctx),
                ),
              ),
              ListTile(
                title: Text('Option B'),
                // 此处context未初始化完毕，使用报错
                // onTap: () => Navigator.pop(context),
              ),
            ],
          ),
        ),
      ),
    );
  }
}

//抽屉头部-->账户类型
class UserDarwerHeader extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return UserAccountsDrawerHeader(
      accountName: Text("slx"),
      accountEmail: Text("xiaofauks@163.com"),
      currentAccountPicture: CircleAvatar(
        backgroundImage:
            NetworkImage("https://www.itying.com/images/flutter/3.png"),
      ),
      decoration: BoxDecoration(
          color: Colors.yellow,
          image: DecorationImage(
              image:
                  NetworkImage("https://www.itying.com/images/flutter/2.png"),
              fit: BoxFit.cover)),
      //右侧图片
      otherAccountsPictures: <Widget>[
        Image.network("https://www.itying.com/images/flutter/4.png"),
        Image.network("https://www.itying.com/images/flutter/5.png"),
      ],
    );
  }
}

class NormalDrawerHeader extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return DrawerHeader(
      child: Text("slx"),
      decoration: BoxDecoration(
          color: Colors.yellow,
          image: DecorationImage(
              image:
                  NetworkImage("https://www.itying.com/images/flutter/2.png"),
              fit: BoxFit.cover)),
    );
  }
}
